#!/usr/bin/env python
#encoding=utf8

"""
@描述：1.redis服务器本身有集群的概念，每个集群负责n1-n2的slots，但是这里用的是客户端将key值写入不同的redis
	   2.由xp-52和xp-80组成的两个独立的集群，它们作为master存在
@作者：范红星
@日期：2014年11月13日 星期四
"""

from redis_shard.shard import RedisShardAPI

if __name__ == "__main__":
	# xp-52下面带着两个slave
	servers = [{'name':'xp-52','host':'xp-52','port':6379,'db':0},{'name':'xp-80','host':'xp-80','port':6379,'db':0}]
	try:
		client = RedisShardAPI(servers)
	except :
		print("-client = RedisShardAPI(servers) is error!!!")
	
	userInfo = {"hongxingfan":"jilin_baicheng",
				"wenxiubi":"heilongjiang_yabuli",
				"guangweicao":"jilin_changchun",
				"huanhuanli":"jilin_baicheng",
				"shishen":"jilin_baicheng"
			}
	for (key,val) in userInfo.items():
		client.set(key,val)

	print("All userInfo is putted into redis!")

	for key in userInfo.keys():
		print("%s:%s" %(key,client.get(key)))
